<template>
  <el-dialog title="整合报告" :visible.sync="visible" width="60%">
    <el-scrollbar style="height: 600px;">
      <quill-editor v-model="mergedContent" contentType="html" style="height: 500px;"></quill-editor>
    </el-scrollbar>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="saveMergedReport">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import QuillEditor from 'vue-quill-editor/src/editor.vue';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

export default {
  components: {
    QuillEditor
  },
  props: ['rows'],
  data() {
    return {
      visible: false,
      mergedContent: ''
    };
  },
  watch: {
    rows(newVal) {
      if (newVal && newVal.length === 2) {
        this.mergedContent = `${newVal[0].fileContent}<hr>${newVal[1].fileContent}`;
      }
    }
  },
  methods: {
    open(rows) {
      this.rows = rows;
      this.visible = true;
    },
    closeDialog() {
      this.visible = false;
    },
    saveMergedReport() {
      const newReport = {
        fileName: `Merged_Report_${Date.now()}.pdf`,
        scanner: this.rows[0].scanner, // 假设合并后的报告使用第一个报告的扫描器
        fileContent: this.mergedContent
      };
      this.$emit('merged', newReport);
      this.closeDialog();
    }
  }
};
</script>
